package com.jml.account.sysUser.service.impl;


import com.jml.account.common.entity.utils.Page;
import com.jml.account.sysUser.dao.SysUserDao;
import com.jml.account.sysUser.entity.SysUser;
import com.jml.account.sysUser.service.SysUserService;
import java.util.HashMap;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class SysUserServiceImpl implements SysUserService {

    @Autowired
    private SysUserDao sysUserDao;


    public void saveUserMessage(SysUser sysUser) {
        if(StringUtils.isEmpty(sysUser.getId())){
            sysUser.preInsert();
            sysUserDao.insert(sysUser);
            int i = 0;
            int i1 = 10 / i;
        }else{
            sysUser.preUpdate();
            sysUserDao.update(sysUser);
        }
    }

    public SysUser selectTest() {
        return sysUserDao.selectTest();
    }

    public SysUser getByLoginName(String loginName) {
        return sysUserDao.getByLoginName(loginName);
    }

    public Page queryPage(HashMap map) {
        Page page =new Page((Integer) map.get("pageno"),(Integer) map.get("pagesize"));


        Integer startIndex = page.getStartIndex();

        map.put("startIndex",startIndex);

        List<SysUser> list = sysUserDao.queryList(map);

        Integer totalsize = sysUserDao.queryCount(map);

        page.setTotalsize(totalsize);

        page.setData(list);

        return page;
    }

    public void insert(SysUser sysUser) {
        sysUserDao.insert(sysUser);
    }

    public SysUser getById(String id) {
        return sysUserDao.getById(id);
    }

    public SysUser getByUserPs(SysUser user) {

        return sysUserDao.getByUserPs(user);
    }
}

